<template>
  <div :class="['add-node-btn-box']">
    <div :class="['add-node-btn', 'affix_' + uid]">
      <a-popover
        :popup-visible="visible"
        position="rt"
        popup-container=".flow-desgin-main"
        content-class="add-node-btn-box-wrap"
        :show-arrow="false"
        @popup-visible-change="onPopupStatusChange">
      </a-popover>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, computed } from "vue";
import Snowflake from "@/components/flowable/flow/common/Snowflake";
import { NODE } from "@/components/flowable/flow/common/FlowConstant";

let emits = defineEmits(["update:childNodeP"]);
let visible = ref(false);
let uid = ref(Snowflake.generate()); //当前组件的id
let props = defineProps({
  childNodeP: {
    type: Object,
    default: () => null,
  },
});

// 节点图标
let icons = reactive({});
icons[NODE.APPROVE] = { icon: "&#xe658" };
icons[NODE.COPY] = { icon: "&#xe656" };
icons[NODE.EXCLUSIVE_GATEWANY] = { icon: "&#xe63f" };
icons[NODE.TRANSACT] = { icon: "&#xe6cd" };
icons[NODE.TRIGGER] = { icon: "&#xe638;" };
icons[NODE.DELAY] = { icon: "&#xe630" };

const onPopupStatusChange = (is) => {
  visible.value = is;
};

</script>

<style scoped lang="less">
.add-node-btn-box {
  width: 240px;
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
  -ms-flex-negative: 0;
  flex-shrink: 0;
  -webkit-box-flex: 1;
  -ms-flex-positive: 1;
  position: relative;

  &:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    margin: auto;
    width: 2px;
    height: 100%;
    background-color: #cacaca;
  }

  .add-node-btn {
    user-select: none;
    width: 240px;
    padding: 28px 0;
    display: flex;
    -webkit-box-pack: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-box-flex: 1;
    flex-grow: 1;
    position: relative;

    .btn {
      outline: none;
      cursor: pointer;
      box-shadow: 0 2px 4px 0 #0000001a;
      width: 30px;
      height: 30px;
      background: #3296fa;
      border-radius: 50%;
      position: relative;
      border: none;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);

      .arco-icon {
        color: #fff;
      }

      &:hover {
        box-shadow: 0 13px 27px 0 #0000001a;
      }

      &:active {
        transform: none;
        background: #1e83e9;
        box-shadow: 0 2px 4px 0 #e5e5e5;
      }
    }
  }
}
</style>

<style lang="less">
.add-node-btn-box-wrap {
  padding: 8px 10px;
  background-color: var(--color-bg-popup);
  border-radius: 4px;
  box-shadow: 0 2px 8px #00000026;
  font-size: 12px;
  cursor: default;

  .arco-popover-content {
    margin-top: 0;
  }

  .add-node-popover-wrap {
    display: flex;

    .add-node-popover-item {
      cursor: pointer;
      border-radius: 4px;
      display: flex;
      flex-direction: column;
      align-items: center;

      + .add-node-popover-item {
        margin-left: 8px;
      }

      &:hover {
        background-color: rgba(31, 35, 41, 0.08);
      }

      .node-icon {
        width: 42px;
        height: 42px;
        border-radius: 50%;
        margin: 6px 4px 4px;
        display: flex;
        align-items: center;
        justify-content: center;

        .iconfont-approval-admin {
          font-size: 40px;
        }
      }

      .node-text {
        text-align: center;
        min-width: 56px;
      }
    }

    .approver {
      .iconfont-approval-admin {
        color: #ff943e;
      }
    }

    .copyer {
      .iconfont-approval-admin {
        color: #3296fa;
      }
    }

    .condition {
      .iconfont-approval-admin {
        color: #2eb795;
      }
    }

    .transactor {
      .iconfont-approval-admin {
        color: #926bd5;
      }
    }

    .trigger {
      .iconfont-approval-admin {
        color: #15BC83;
      }
    }
    .delay {
      .iconfont-approval-admin {
        color: #f25643;
      }
    }
  }
}
</style>
